package com.rondo.CurrencyFramework.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rondo.CurrencyFramework.dao.UserDao;
import com.rondo.CurrencyFramework.domain.User;
import com.rondo.CurrencyFramework.exception.CustomException;
import com.rondo.CurrencyFramework.serviceImpl.UserServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api(tags = "1.1", value = "用户管理")
public class UserController {

    @Autowired
    private UserServiceImpl userService;

    @GetMapping(value = "getUserList")
    @ApiOperation(value = "查询所有用户列表")
    public List<User> getUserList(){
        return  userService.getUserList();
    }


    @GetMapping(value = "getUserPageList")
    @ApiOperation(value = "分页查询用户列表")
    public PageInfo<Object> getUserPageList(int pageIndex){
        if (pageIndex == 0) {
            throw new CustomException(400, "pageIndex不能为0");
        }
        final PageInfo<Object> pageInfo = PageHelper.startPage(pageIndex, 10).setOrderBy("id desc").doSelectPageInfo(() -> this.userService.getUserPageList());
        return  pageInfo;
    }
}
